function DataRepository(dispatcher)
{
    this.dispatcher = dispatcher;

    this.dispatcher.on("need_sections_reload", this.loadSections, this);
}

DataRepository.prototype = {

    api: function(uri) {
        return 'http://pa.stepanets.org' + uri;
    },

    loadSites: function() {
        $.ajax({
            dataType: "json",
            url: this.api('/site?format=json&callback=?'),
            context: this,
            success: function(data) {
                if( data.error && data.error.code ) {
                    throw data.error.message;
                };

                this.dispatcher.trigger("sites_loaded", data.sites);
            }
        });
    },

    loadSections: function() {
        $.ajax({
            dataType: "json",
            url: this.api('/url?format=json&callback=?'),
            context: this,
            success: function(data) {
                if( data.error && data.error.code ) {
                    throw data.error.message;
                };

                this.dispatcher.trigger("sections_loaded", data.urls);
            }
        });
    },

    saveCurrentSite: function(Site) {
        $.cookie('current_site', Site.id);
    },

    getCurrentSite: function() {
        $.cookie('current_site');
    }

};